package com.example.kcp.output;

import com.example.kcp.enums.CommandCode;
import com.example.kcp.message.ProtocolMessage;

/**
 * @author "陈凯航"
 * @date 2024/10/7
 * @mail "mengxingcn@aliyun.com"
 */
public abstract class BaseBuilder<T> {
    protected byte[] authorizationCode;
    protected byte messageType = 0x00;
    protected short sequenceNumber = 0;
    protected CommandCode commandCode;
    protected short dataLength;
    protected byte[] data;

    public ProtocolMessage build() {
        return ProtocolMessage.of(this.authorizationCode, this.messageType, this.sequenceNumber, this.commandCode, this.buildDataLength(), this.buildData());
    }

    protected abstract byte[] buildData();

    protected abstract short buildDataLength();
}
